package com.cheng.im.service.massage.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cheng.im.service.common.resp.CommonResult;
import com.cheng.im.service.massage.mapper.ImMessageHistoryMapper;
import com.cheng.im.service.message.domain.ImMessageHistory;
import com.cheng.im.service.message.model.resp.LastMessageResp;
import com.cheng.im.service.message.model.resp.MessageListResp;
import com.cheng.im.service.message.service.ImMessageHistoryService;
import org.apache.dubbo.config.annotation.DubboService;

import java.util.Collections;
import java.util.List;

/**
* @author Cheng
* @description 针对表【im_message_history】的数据库操作Service实现
* @createDate 2025-01-09 08:19:12
*/
@DubboService
public class ImMessageHistoryServiceImpl extends ServiceImpl<ImMessageHistoryMapper, ImMessageHistory>
    implements ImMessageHistoryService {

    @Override
    public CommonResult<LastMessageResp> getUserLastMessage(String fromId, String toId, String appId) {
        LastMessageResp userLastMessage = baseMapper.getUserLastMessage(fromId, toId, appId);
        return CommonResult.success(userLastMessage);
    }

    @Override
    public CommonResult<List<MessageListResp>> getMsgListByUserId(String ownerId, String from, String to, String appId) {

        List<MessageListResp> msgListByUserId = baseMapper.getMsgListByUserId(ownerId, from, to, appId);
        Collections.reverse(msgListByUserId);

        return CommonResult.success(msgListByUserId);
    }
}




